package com.carrental.api.oms.controller;


import com.carrental.common.response.CommonPage;
import com.carrental.common.response.CommonResult;
import com.carrental.api.common.query.CommonQueryParam;
import com.carrental.api.oms.domain.OmsReturnCheck;
import com.carrental.api.oms.domain.bo.OmsReturnCheckPost;
import com.carrental.api.oms.service.IOmsReturnCheckService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 出车检查单 前端控制器
 * </p>
 *
 * @author 梁毅
 * @since 2022-03-07 23:12:15
 */
@RestController
@Api(tags = "还车检查单管理")
@RequestMapping("/api/serve/return-check")
public class OmsReturnCheckController {
    @Autowired
    private IOmsReturnCheckService returnCheckService;

    @PostMapping()
    @ApiOperation("生成还车检查单")
    @Transactional(rollbackFor = Exception.class)
    public CommonResult<Boolean> returnCheckCreate(@RequestBody OmsReturnCheckPost returnCheck) {
        return CommonResult.success(returnCheckService.create(returnCheck));
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除还车检查单信息")
    @Transactional(rollbackFor = Exception.class)
    public CommonResult<Boolean> returnCheckRemove(@ApiParam(name = "id", value = "检查单", required = true)
                                                   @PathVariable Long id) {
        return CommonResult.success(returnCheckService.delete(id));
    }

    @PutMapping("/{id}")
    @ApiOperation("修改还车检查单信息")
    @Transactional(rollbackFor = Exception.class)
    public CommonResult<Boolean> returnCheckUpdate(@ApiParam(name = "id", value = "检查单标识", required = true)
                                                   @PathVariable Long id, @RequestBody OmsReturnCheckPost returnCheck) {
        return CommonResult.success(returnCheckService.update(id,returnCheck));
    }

    @GetMapping()
    @ApiOperation("获取还车检查单列表")
    public CommonResult<List<OmsReturnCheck>> returnCheckList(CommonQueryParam commonQueryParam) {
        return CommonResult.success(returnCheckService.list(commonQueryParam));
    }

    @GetMapping("/{id}")
    @ApiOperation("获取还车检查单详情")
    public CommonResult<OmsReturnCheck> returnCheckObj(@PathVariable Long id) {
        return CommonResult.success(returnCheckService.detail(id));
    }

    @GetMapping("/page")
    @ApiOperation("获取还车检查单分页")
    public CommonResult<CommonPage<OmsReturnCheck>> returnCheckPage(CommonQueryParam commonQueryParam) {
        return CommonResult.success(CommonPage.restPage(returnCheckService.pageList(commonQueryParam)));
    }
}
